load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_integration_test", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

mongo_cc_library(
    name = "remote_command",
    srcs = [
        "remote_command_request.cpp",
        "remote_command_response.cpp",
    ],
    hdrs = [
        "remote_command_request.h",
        "remote_command_response.h",
    ],
    deps = [
        "//src/mongo/db:api_parameters",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/auth:security_token_auth",  # TODO(SERVER-93876): Remove.
        "//src/mongo/rpc:metadata",  # TODO(SERVER-93876): Remove.
        "//src/mongo/s:mongos_server_parameters",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:fail_point",
        "//src/mongo/util/net:network",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "task_executor_interface",
    srcs = [
        "task_executor.cpp",
    ],
    hdrs = [
        "task_executor.h",
    ],
    deps = [
        ":remote_command",
        "//src/mongo:base",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "async_multicaster",
    srcs = [
        "async_multicaster.cpp",
    ],
    hdrs = [
        "async_multicaster.h",
    ],
    deps = [
        ":remote_command",
        ":task_executor_interface",  # TODO(SERVER-93876): Remove.
        "//src/mongo:base",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util/net:network",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "scoped_task_executor",
    srcs = [
        "scoped_task_executor.cpp",
    ],
    hdrs = [
        "scoped_task_executor.h",
    ],
    deps = [
        ":task_executor_interface",
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "network_interface",
    srcs = [
        "network_interface.cpp",
    ],
    hdrs = [
        "network_interface.h",
    ],
    deps = [
        ":task_executor_interface",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:fail_point",
    ],
)

mongo_cc_library(
    name = "thread_pool_task_executor",
    srcs = [
        "thread_pool_task_executor.cpp",
    ],
    hdrs = [
        "thread_pool_task_executor.h",
    ],
    deps = [
        ":network_interface",  # TODO(SERVER-93876): Remove.
        ":task_executor_interface",
        "//src/mongo/db:service_context",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:future_util",
    ],
)

mongo_cc_library(
    name = "inline_executor",
    srcs = [
        "inline_executor.cpp",
        "//src/mongo/util:producer_consumer_queue.h",
    ],
    hdrs = [
        "inline_executor.h",
    ],
    deps = [
        ":task_executor_interface",
        "//src/mongo:base",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "pinned_connection_task_executor",
    srcs = [
        "pinned_connection_task_executor.cpp",
    ],
    hdrs = [
        "pinned_connection_task_executor.h",
    ],
    deps = [
        "scoped_task_executor",
        "task_executor_interface",  # TODO(SERVER-93876): Remove.
        "//src/mongo/client:async_client",
    ],
)

mongo_cc_library(
    name = "pinned_connection_task_executor_factory",
    srcs = [
        "pinned_connection_task_executor_factory.cpp",
    ],
    hdrs = [
        "pinned_connection_task_executor_factory.h",
    ],
    deps = [
        ":network_interface",  # TODO(SERVER-93876): Remove.
        ":pinned_connection_task_executor",
        ":task_executor_interface",  # TODO(SERVER-93876): Remove.
        ":thread_pool_task_executor",
    ],
)

mongo_cc_library(
    name = "egress_connection_closer_manager",
    srcs = [
        "egress_connection_closer_manager.cpp",
    ],
    hdrs = [
        "egress_connection_closer_manager.h",
    ],
    deps = [
        "//src/mongo/db:service_context",
    ],
)

idl_generator(
    name = "network_interface_tl_gen",
    src = "network_interface_tl.idl",
)

mongo_cc_library(
    name = "network_interface_tl",
    srcs = [
        "connection_pool_tl.cpp",
        "exhaust_response_reader_tl.cpp",
        "network_interface_tl.cpp",
        ":network_interface_tl_gen",
        "//src/mongo/util:strong_weak_finish_line.h",
    ],
    hdrs = [
        "connection_pool_tl.h",
        "exhaust_response_reader_tl.h",
        "network_interface_tl.h",
    ],
    deps = [
        ":connection_pool_executor",
        ":network_interface",
        "//src/mongo/client:async_client",
        "//src/mongo/db:server_feature_flags",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db/auth",
        "//src/mongo/db/commands:server_status_core",  # TODO(SERVER-93876): Remove.
        "//src/mongo/transport:transport_layer",  # TODO(SERVER-93876): Remove.
        "//src/mongo/transport:transport_layer_manager",
    ],
)

mongo_cc_library(
    name = "network_interface_factory",
    srcs = [
        "network_interface_factory.cpp",
    ],
    hdrs = [
        "network_interface_factory.h",
    ],
    deps = [
        ":connection_pool_executor",  # TODO(SERVER-93876): Remove.
        ":egress_connection_closer_manager",  # TODO(SERVER-93876): Remove.
        ":network_interface",  # TODO(SERVER-93876): Remove.
        ":network_interface_tl",
    ],
)

idl_generator(
    name = "task_executor_pool_parameters_gen",
    src = "task_executor_pool_parameters.idl",
)

mongo_cc_library(
    name = "task_executor_cursor",
    srcs = [
        "task_executor_cursor.cpp",
        "task_executor_cursor_options.cpp",
        ":task_executor_cursor_parameters_gen",
    ],
    hdrs = [
        "task_executor_cursor.h",
        "task_executor_cursor_options.h",
    ],
    deps = [
        ":pinned_connection_task_executor_factory",
        ":task_executor_interface",
        "//src/mongo/db/query:command_request_response",
        "//src/mongo/db/query:plan_yield_policy",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "task_executor_pool",
    srcs = [
        "task_executor_pool.cpp",
        "task_executor_pool_parameters_gen",
    ],
    hdrs = [
        "task_executor_pool.h",
    ],
    deps = [
        ":task_executor_interface",
        "//src/mongo/db:server_base",
        "//src/mongo/util:processinfo",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "async_request_executor",
    srcs = [
        "async_request_executor.cpp",
    ],
    hdrs = [
        "async_request_executor.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:service_context",
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util/concurrency:thread_pool",
    ],
)

idl_generator(
    name = "task_executor_cursor_parameters_gen",
    src = "task_executor_cursor_parameters.idl",
)

mongo_cc_library(
    name = "async_rpc_error_info",
    srcs = [
        "async_rpc_error_info.cpp",
    ],
    hdrs = [
        "async_rpc_error_info.h",
        "//src/mongo/client:read_preference.h",
        "//src/mongo/client:read_preference_gen",
        "//src/mongo/client:read_preference_validators.h",
        "//src/mongo/db:change_stream_state_gen",
        "//src/mongo/db:json.h",
        "//src/mongo/db:read_write_concern_provenance_base_gen",
        "//src/mongo/db:shard_id.h",
        "//src/mongo/db/auth:parsed_privilege_gen",
        "//src/mongo/db/auth:role_name_or_string.h",
        "//src/mongo/db/commands:create_gen",
        "//src/mongo/db/commands/query_cmd:explain_gen",
        "//src/mongo/db/index_builds:resumable_index_builds_gen",
        "//src/mongo/db/repl:oplog_entry_gen",
        "//src/mongo/db/repl:read_concern_args.h",
        "//src/mongo/db/repl:repl_set_config_gen",
        "//src/mongo/db/sorter:sorter_gen",
        "//src/mongo/executor:remote_command_response.h",
        "//src/mongo/idl:generic_argument.h",
        "//src/mongo/idl:generic_argument_gen",
        "//src/mongo/rpc:get_status_from_command_result.h",
        "//src/mongo/rpc/metadata:impersonated_user_metadata_gen",
        "//src/mongo/s:chunk_version.h",
        "//src/mongo/s:database_version.h",
        "//src/mongo/s:database_version_base_gen",
        "//src/mongo/s:gossiped_routing_cache_gen",
        "//src/mongo/s:index_version.h",
        "//src/mongo/s:shard_version.h",
    ],
    header_deps = [
        "//src/mongo/bson/column",
        "//src/mongo/db/concurrency:flow_control_ticketholder",
        "//src/mongo/db/exec/sbe:query_sbe_plan_stats",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "network_interface_thread_pool",
    srcs = [
        "network_interface_thread_pool.cpp",
    ],
    hdrs = [
        "//src/mongo/client:async_client.h",
        "//src/mongo/client:authenticate.h",
        "//src/mongo/client:internal_auth.h",
        "//src/mongo/client:mongo_uri.h",
        "//src/mongo/client:read_preference_gen",
        "//src/mongo/client:sasl_client_session.h",
        "//src/mongo/db:set_change_stream_state_coordinator_gen",
        "//src/mongo/db:vector_clock_gen",
        "//src/mongo/db:write_concern_gen",
        "//src/mongo/db/commands:list_databases_for_all_tenants_gen",
        "//src/mongo/db/commands/query_cmd:explain_gen",
        "//src/mongo/db/index_builds:resumable_index_builds_gen",
        "//src/mongo/db/repl:repl_set_config_gen",
        "//src/mongo/db/sorter:sorter_gen",
        "//src/mongo/executor:connection_metrics.h",
        "//src/mongo/executor:network_connection_hook.h",
        "//src/mongo/executor:network_interface.h",
        "//src/mongo/executor:network_interface_thread_pool.h",
        "//src/mongo/executor:remote_command_request.h",
        "//src/mongo/executor:task_executor.h",
        "//src/mongo/idl:generic_argument_gen",
        "//src/mongo/logv2:log_severity_suppressor.h",
        "//src/mongo/rpc:metadata.h",
        "//src/mongo/rpc:protocol.h",
        "//src/mongo/rpc:reply_interface.h",
        "//src/mongo/rpc:unique_message.h",
        "//src/mongo/s:database_version_gen",
        "//src/mongo/s:gossiped_routing_cache_gen",
        "//src/mongo/s:refresh_query_analyzer_configuration_cmd_gen",
        "//src/mongo/s:shard_version_gen",
        "//src/mongo/transport:baton.h",
        "//src/mongo/transport:message_compressor_base.h",
        "//src/mongo/transport:message_compressor_manager.h",
        "//src/mongo/transport:ssl_connection_context.h",
        "//src/mongo/transport:transport_layer.h",
        "//src/mongo/util:destructor_guard.h",
        "//src/mongo/util/concurrency:thread_pool_interface.h",
        "//src/mongo/util/net:sock.h",
        "//src/mongo/util/net:ssl_manager.h",
        "//src/mongo/util/net:ssl_options.h",
        "//src/mongo/util/net/ssl:apple.hpp",
    ],
    header_deps = [
        "//src/mongo/db/concurrency:flow_control_ticketholder",
        "//src/mongo/db/exec/sbe:query_sbe_plan_stats",
        "//src/mongo/executor:async_rpc_error_info",
        "//src/mongo/platform:visibility_test_libcommon",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "connection_pool_stats",
    srcs = [
        "connection_pool_stats.cpp",
    ],
    hdrs = [
        "connection_pool_stats.h",
    ],
    header_deps = [
        "//src/mongo/db/commands:server_status_core",
    ],
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/util/net:network",
    ],
)

mongo_cc_library(
    name = "connection_pool_executor",
    srcs = [
        "connection_pool.cpp",
    ],
    hdrs = [
        "connection_pool.h",
    ],
    deps = [
        ":connection_pool_stats",
        ":egress_connection_closer_manager",
        ":remote_command",  # TODO(SERVER-93876): Remove.
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util:fail_point",  # TODO(SERVER-93876): Remove.
        "//src/mongo/util/net:network",  # TODO(SERVER-93876): Remove.
    ],
)

mongo_cc_library(
    name = "connection_pool_controllers",
    srcs = [
        "connection_pool_controllers.cpp",
    ],
    hdrs = [
        "connection_pool_controllers.h",
    ],
    deps = [
        ":connection_pool_executor",
    ],
)

mongo_cc_library(
    name = "async_rpc",
    srcs = [
        "async_rpc.cpp",
    ],
    hdrs = [
        "async_rpc.h",
    ],
    deps = [
        ":async_rpc_error_info",
        ":remote_command",
        ":task_executor_interface",
        "//src/mongo:base",
        "//src/mongo/db:commands",
        "//src/mongo/db:server_base",
        "//src/mongo/db/commands:kill_common",
        "//src/mongo/rpc:command_status",
    ],
)

mongo_cc_library(
    name = "mock_async_rpc",
    hdrs = [
        "mock_async_rpc.h",
    ],
    deps = [
        ":async_rpc",
    ],
)

mongo_cc_library(
    name = "network_interface_mock",
    srcs = [
        "mock_network_fixture.cpp",
        "network_interface_mock.cpp",
        "thread_pool_mock.cpp",
    ],
    hdrs = [
        "mock_network_fixture.h",
        "network_interface_mock.h",
        "thread_pool_mock.h",
    ],
    deps = [
        ":network_interface",
        ":task_executor_interface",
        "//src/mongo:base",
        "//src/mongo/db:query_expressions",
        "//src/mongo/rpc:metadata",
        "//src/mongo/util:clock_source_mock",
        "//src/mongo/util/net:network",
    ],
)

mongo_cc_library(
    name = "async_timer_mock",
    srcs = [
        "async_timer_mock.cpp",
    ],
    hdrs = [
        "async_timer_interface.h",
        "async_timer_mock.h",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/base:system_error",
    ],
)

mongo_cc_library(
    name = "network_test_env",
    srcs = [
        "network_test_env.cpp",
    ],
    hdrs = [
        "network_test_env.h",
    ],
    deps = [
        ":network_interface_mock",
        ":task_executor_interface",
        "//src/mongo/db:commands",
        "//src/mongo/db/query:command_request_response",
        "//src/mongo/unittest",
    ],
)

mongo_cc_library(
    name = "task_executor_test_fixture",
    srcs = [
        "task_executor_test_common.cpp",
        "task_executor_test_fixture.cpp",
    ],
    hdrs = [
        "task_executor_test_common.h",
        "task_executor_test_fixture.h",
    ],
    deps = [
        ":network_interface_mock",
        ":task_executor_interface",
        "//src/mongo/unittest",
        "//src/mongo/util:clock_source_mock",
    ],
)

mongo_cc_library(
    name = "thread_pool_task_executor_test_fixture",
    srcs = [
        "thread_pool_task_executor_test_fixture.cpp",
    ],
    hdrs = [
        "thread_pool_task_executor_test_fixture.h",
    ],
    deps = [
        ":task_executor_test_fixture",
        ":thread_pool_task_executor",
    ],
)

mongo_cc_library(
    name = "network_interface_fixture",
    srcs = [
        "network_interface_integration_fixture.cpp",
    ],
    hdrs = [
        "executor_integration_test_fixture.h",
        "network_interface_integration_fixture.h",
    ],
    deps = [
        "//src/mongo/executor:network_interface_factory",
        "//src/mongo/executor:network_interface_thread_pool",
        "//src/mongo/executor:thread_pool_task_executor",
        "//src/mongo/rpc:command_status",
        "//src/mongo/unittest:integration_test_main",
        "//src/mongo/util:version_impl",
        "//src/mongo/util/concurrency:thread_pool",
    ],
)

mongo_cc_unit_test(
    name = "network_executor_test",
    srcs = [
        "async_rpc_test.cpp",
        "async_rpc_test_fixture.h",
        "async_rpc_util_test.cpp",
        "async_transaction_rpc.h",
        "connection_pool_test.cpp",
        "connection_pool_test_fixture.cpp",
        "connection_pool_test_fixture.h",
        "mock_async_rpc.h",
        "mock_async_rpc_test.cpp",
        "mock_network_fixture_test.cpp",
        "network_interface_mock_test.cpp",
        "network_interface_mock_test_fixture.cpp",
        "network_interface_mock_test_fixture.h",
        "pinned_connection_task_executor_test.cpp",
        "pinned_connection_task_executor_test_fixture.h",
        "test_network_connection_hook.h",
        "//src/mongo/transport:mock_session.h",
        "//src/mongo/transport:test_fixtures.h",
        "//src/mongo/transport:transport_layer_mock.h",
        "//src/mongo/unittest:join_thread.h",
        "//src/mongo/util:executor_test_util.h",
    ],
    tags = ["mongo_unittest_third_group"],
    deps = [
        "async_rpc",
        "connection_pool_executor",
        "egress_connection_closer_manager",
        "network_interface_mock",
        "network_interface_tl",
        "network_test_env",
        "pinned_connection_task_executor",
        "thread_pool_task_executor_test_fixture",
        "//src/mongo/client:remote_command_targeter",
        "//src/mongo/client:remote_command_targeter_mock",
        "//src/mongo/db:service_context_non_d",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db/commands:standalone",
        "//src/mongo/db/repl:hello_command",
        "//src/mongo/db/repl:task_executor_mock",
        "//src/mongo/util:clock_source_mock",
    ],
)

mongo_cc_unit_test(
    name = "task_executor_test",
    srcs = [
        "cancelable_executor.h",
        "cancelable_executor_test.cpp",
        "inline_executor_test.cpp",
        "pinned_connection_task_executor_test_fixture.h",
        "scoped_task_executor_test.cpp",
        "split_timer_test.cpp",
        "task_executor_cursor_test.cpp",
        "task_executor_cursor_test_fixture.h",
        "thread_pool_task_executor_test.cpp",
        "//src/mongo/transport:mock_session.h",
        "//src/mongo/transport:test_fixtures.h",
        "//src/mongo/transport:transport_layer_mock.h",
        "//src/mongo/unittest:join_thread.h",
        "//src/mongo/util:executor_test_util.h",
    ],
    tags = [
        "mongo_unittest_second_group",
        "server-programmability",
    ],
    deps = [
        "inline_executor",
        "scoped_task_executor",
        "task_executor_cursor",
        "thread_pool_task_executor",
        "thread_pool_task_executor_test_fixture",
        "//src/mongo/db:service_context_non_d",
        "//src/mongo/db:service_context_test_fixture",
    ],
)

mongo_cc_integration_test(
    name = "executor_integration_test",
    srcs = [
        "executor_integration_test_fixture.cpp",
        "exhaust_response_reader_integration_test.cpp",
        "network_interface_integration_test.cpp",
        "task_executor_cursor_integration_test.cpp",
        "thread_pool_task_executor_integration_test.cpp",
    ],
    deps = [
        "network_interface_fixture",
        "network_interface_tl",
        "task_executor_cursor",
        "//src/mongo/client:async_client",
        "//src/mongo/client:clientdriver_network",
        "//src/mongo/db:wire_version",
        "//src/mongo/db/commands:kill_operations_idl",
        "//src/mongo/db/query/client_cursor:cursor_response_idl",
        "//src/mongo/db/query/write_ops:write_ops_parsers",
        "//src/mongo/executor:network_interface_factory",
        "//src/mongo/executor:network_interface_thread_pool",
        "//src/mongo/executor:pinned_connection_task_executor",
        "//src/mongo/executor:thread_pool_task_executor",
        "//src/mongo/transport:transport_layer_egress_init",
        "//src/mongo/util:version_impl",
        "//src/mongo/util/concurrency:thread_pool",
    ],
)
